<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="名称" prop="fcorporationname">
        <el-input
          v-model="queryParams.fcorporationname"
          placeholder="请输入单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入关键字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分发时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 440px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['result:materi:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['result:materi:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['result:materi:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-if = false
          type="warning"
          icon="el-icon-upload2"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      border
      :data="tableData"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="分发编号"
        align="center"
        prop="fbillcode"
        width="140"
      />
      <el-table-column label="单位名称" prop="fcorporationname" />
      <el-table-column
        label="开始时间"
        align="center"
        :formatter="formatDate"
        prop="fcreatetime"
        width="140"
      />
      <el-table-column
        label="办结时间"
        align="center"
        :formatter="formatDate"
        prop="ffinishedtime"
        width="140"
      />
      <el-table-column
        label="缴费方式"
        align="center"
        prop="fpaymentmethods"
        width="140"
      />
      <el-table-column
        label="发图单返回情况"
        align="center"
        :formatter="formatterStatus"
        prop="freturnsituation"
        width="140"
      />
      <el-table-column
        label="资料是否齐全"
        align="center"
        prop="fiscompletematerial"
        width="140"
      />
      <el-table-column
        label="分发状态"
        align="center"
        :formatter="formatterIssuesStatus"
        prop="fissuedstate"
        width="140"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="220"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 导入申请单对话框 -->
    <el-dialog v-bind="$attrs" width="20%" v-on="$listeners" :visible.sync="openImport"  title="导入申请单">
      <el-form ref="elForm" size="medium" label-width="100px">
       <importmateriapply ref="importmateriapply" @materiApplyListSearch="getList"></importmateriapply>
      </el-form>
    </el-dialog>
    <!-- 添加或修改申请单对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="80%"
      append-to-body
      :modal-append-to-body="false"
      :close-on-click-modal="false"
    >
      <el-tabs v-model="activeMainTabName" @tab-click="handleMainTabClick" style="padding-left: 2px; padding-right: 2px;">
        <el-tab-pane
          label="成果分发申请单"
          name="applyDocTab"
          :key="'applyDocTab'"
          disabled
        >
          <div class="el-dialog-div" style="height: 72vh; overflow-y: scroll">
            <el-form
              ref="form"
              :model="form"
              :rules="rules"
              label-width="150px"
              height="900px"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="单位名称" prop="fcorporationname">
                    <el-select
                      v-model="form.fcorporationname"
                      placeholder="请选择单位"
                      style="width: 100%"
                      filterable
                      @blur="selectBlur"
                      @change="selectCustomer"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="customer in customerInfoOptions"
                        :key="customer.fguid"
                        :label="customer.fcorporationname"
                        :value="customer.fcorporationname"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="法定代表人" prop="flegalperson">
                    <el-input
                      v-model="form.flegalperson"
                      placeholder="请输入法定代表人"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="详细地址" prop="faddress">
                    <el-input
                      v-model="form.faddress"
                      placeholder="请输入详细地址"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="邮政编码" prop="fzipcode">
                    <el-input
                      v-model="form.fzipcode"
                      placeholder="请输入邮政编码"
                      maxlength="8"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所处县市" prop="fcounty">
                    <treeselect
                      :disable-branch-nodes="true"
                      v-model="form.fcounty"
                      :options="countyOptions"
                      :normalizer="normalizer"
                      :show-count="true"
                      :defaultExpandLevel="1"
                      placeholder="选择所处县市"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="单位类型" prop="fcorporationtype">
                    <treeselect
                      :disable-branch-nodes="true"
                      v-model="form.fcorporationtype"
                      :options="companyTypeOptions"
                      :normalizer="normalizer"
                      :show-count="true"
                      :defaultExpandLevel="1"
                      placeholder="选择单位类型"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12" label-width="200px">
                  <el-form-item
                    label="单位管理保密资料的机构、负责人"
                    prop="fcoandmanager"
                  >
                    <el-input
                      type="textarea"
                      v-model="form.fcoandmanager"
                      placeholder="请输入单位管理保密资料的机构、负责人"
                      :rows="4"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="联系电话" prop="fcontacttel">
                    <el-input
                      v-model="form.fcontacttel"
                      placeholder="请输入联系电话"
                      maxlength="11"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所属行业" prop="findustry">
                    <el-select
                      v-model="form.findustry"
                      placeholder="请选择所属行业"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in industryOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="提供方式" prop="fsupplyway">
                    <el-select
                      v-model="form.fsupplyway"
                      placeholder="请选择提供方式"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in supplywayOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="缴费方式" prop="fpaymentmethods">
                    <el-select
                      v-model="form.fpaymentmethods"
                      placeholder="请选择缴费方式"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in paymentmethodsOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item
                    label-width="180px"
                    label="申请单位组织代码证证号"
                    prop="forgcreditnum"
                  >
                    <el-input
                      v-model="form.forgcreditnum"
                      placeholder="请输入申请单位组织代码证证号"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="是否通过资质审查" prop="fischeckedqa">
                    <el-select
                      v-model="form.fischeckedqa"
                      placeholder="请选择是否通过资质审查"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in ischeckedqaOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="通过资质审查时间" prop="fcheckeddate">
                    <el-date-picker
                      v-model="form.fcheckeddate"
                      size="small"
                      value-format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="客户经办人" prop="FAgreementNum">
                    <el-input
                      v-model="form.fmanagername"
                      placeholder="请输入客户经办人"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="协议编号" prop="fagreementnum">
                    <el-input
                      v-model="form.fagreementnum"
                      placeholder="请输入协议编号"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="身份证号" prop="fidcardnum">
                    <el-input
                      v-model="form.fidcardnum"
                      placeholder="请输入身份证号"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="领图人" prop="fclaimperson">
                    <el-input
                      v-model="form.fclaimperson"
                      placeholder="请输入领图人"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="领图日期" prop="fclaimdate">
                    <el-date-picker
                      v-model="form.fclaimdate"
                      size="small"
                      value-format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="用途" prop="fuse">
                    <el-select
                      v-model="form.fuse"
                      placeholder="请选择用途"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in useOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否有偿" prop="fispaid">
                    <el-select
                      v-model="form.fispaid"
                      placeholder="请输入是否有偿"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in ispaidOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="外省测绘局审批人" prop="fprovapprover">
                    <el-input
                      v-model="form.fprovapprover"
                      placeholder="请输入外省测绘局审批人"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="外省测绘局审批日期"
                    prop="fprovapprovedate"
                  >
                    <el-date-picker
                      v-model="form.fprovapprovedate"
                      size="small"
                      value-format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="开始时间" prop="fcreatetime">
                    <el-date-picker
                      v-model="form.fcreatetime"
                      size="small"
                      value-format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="办结时间" prop="ffinishedtime">
                    <el-date-picker
                      v-model="form.ffinishedtime"
                      size="small"
                      value-format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                      :disabled="!canEdit"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="使用期限" prop="flifespan">
                    <el-input
                      v-model="form.flifespan"
                      placeholder="请输入使用期限"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="成果名称" prop="fresultname">
                    <el-input
                      v-model="form.fresultname"
                      placeholder="请输入成果名称"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目类型" prop="fprjtype">
                    <el-select
                      v-model="form.fprjtype"
                      placeholder="请选择项目类型"
                      style="width: 100%"
                      :disabled="!canEdit"
                    >
                      <el-option
                        v-for="dict in prjtypeOptions"
                        :key="dict.fcode"
                        :label="dict.fcontent"
                        :value="dict.fcode"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目来源" prop="fprjfrom">
                    <el-input
                      v-model="form.fprjfrom"
                      placeholder="请输入项目来源"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="使用目的" prop="fusepurpose">
                    <el-input
                      v-model="form.fusepurpose"
                      placeholder="请输入使用目的"
                      :disabled="!canEdit"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-tab-pane>
        <el-tab-pane
          label="成果分发明细"
          name="orderItemTab"
          :key="'orderItemTab'"
          disabled
        >
          <div
            class="el-dialog-div"
            style="height: 72vh; width: 100%; overflow: auto"
          >
            <el-row>
              <el-col :span="24">
                <el-tabs
                  type="border-card"
                  v-model="activeName"
                  @tab-click="handleClick"
                >
                  <el-tab-pane
                    label="地理国情"
                    style="height: auto; width: 100%; overflow: auto"
                    name="diliguoqing"
                    :key="'diliguoqing'"
                  >
                    <diliguoqing ref="diliguoqing"></diliguoqing>
                  </el-tab-pane>
                  <el-tab-pane
                    label="航摄成果"
                    style="height: auto; width: 100%; overflow: auto"
                    name="hangshe"
                    :key="'hangshe'"
                  >
                    <hangshe ref="hangshe"></hangshe>
                  </el-tab-pane>
                  <el-tab-pane
                    label="加密成果"
                    style="height: auto; width: 100%; overflow: auto"
                    name="jiami"
                    :key="'jiami'"
                  >
                    <jiami ref="jiami"></jiami>
                  </el-tab-pane>
                  <el-tab-pane
                    label="卫星影像"
                    style="height: auto; width: 100%; overflow: auto"
                    name="weixing"
                    :key="'weixing'"
                  >
                    <weixing ref="weixing"></weixing>
                  </el-tab-pane>
                  <el-tab-pane
                    label="其他"
                    style="height: auto; width: 100%; overflow: auto"
                    name="qita"
                    :key="'qita'"
                  >
                    <qita ref="qita"></qita>
                  </el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="nextStep"
          v-if="firstTabIsShow"
          icon="el-icon-arrow-right"
          >下一步</el-button
        >
        <el-button
          type="primary"
          @click="backStep"
          v-if="!firstTabIsShow"
          icon="el-icon-arrow-left"
          >上一步</el-button
        >
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMateri,
  getMateri,
  delMateri,
  addMateri,
  updateMateri,
  listCounty,
  listDataDic,
  guid,
} from "@/api/materi/materi";
import { miniListCustomer, getCustomer} from "@/api/materi/custom";

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

import diliguoqing from "../orderitems/diliguoqing";
import hangshe from "../orderitems/hangshe";
import jiami from "../orderitems/jiami";
import weixing from "../orderitems/weixing";
import qita from "../orderitems/qita";
import importmateriapply from "../materi/importmateriapply";

export default {
  name: "materi",
  components: { Treeselect, diliguoqing, hangshe, jiami, weixing, qita, importmateriapply },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //所在县市区数据
      countyOptions: [],
      //单位类型
      companyTypeOptions: [],
      //所属行业
      industryOptions: [],
      //提供方式
      supplywayOptions: [
        { fcode: "打印", fcontent: "打印" },
        { fcode: "拷贝", fcontent: "拷贝" },
        { fcode: "印刷", fcontent: "印刷" },
      ],
      //是否通过资质审查
      ischeckedqaOptions: [
        { fcode: "yes", fcontent: "是" },
        { fcode: "no", fcontent: "否" },
      ],
      //用途
      useOptions: [
        { fcode: "u01", fcontent: "一般用途" },
        { fcode: "u02", fcontent: "应急保障" },
      ],
      //分发类型列表
      detailOptions: [
        { fcode: "u01", fcontent: "一般用途" },
        { fcode: "u02", fcontent: "应急保障" },
      ],
      //是否有偿
      ispaidOptions: [
        { fcode: "有偿", fcontent: "有偿" },
        { fcode: "无偿", fcontent: "无偿" },
      ],
      //缴费方式
      paymentmethodsOptions: [
        { fcode: "结清", fcontent: "结清" },
        { fcode: "记账", fcontent: "记账" },
      ],
      prjtypeOptions: [
        { fcode: "典型应用项目", fcontent: "典型应用项目" },
        { fcode: "国省级重点项目", fcontent: "国省级重点项目" },
        { fcode: "市级重点项目", fcontent: "市级重点项目" },
        { fcode: "热点项目", fcontent: "热点项目" },
      ],
      // 总条数
      total: 0,
      // 测试样例表格数据
      tableData: [],
      //form表单的数据是否再初始化后发生了改动
      formIsChange: false,
      // 日期范围
      dateRange: [],
      //客户信息列表
      customerInfoOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //当前明细Tab页名称
      activeName: "",
      //当前主tab页名称
      activeMainTabName: "",
      //申请单tab页是否已显示
      firstTabIsShow: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fcorporationname: undefined,
        keyword: undefined,
        beginTime: undefined,
        endTime: undefined,
        fdatasource: "补录",
      },
      // 客户信息查询参数
      queryCustomParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      formMode: "",
      // 表单校验
      rules: {
        fcorporationname:[{required: true, message: '请输入单位名称', trigger: 'blur'}],
        fcounty:[{required: true, message: '请输入所在县市区', trigger: 'blur'}],
        faddress:[{required: true, message: '请输入详细地址', trigger: 'blur'}],
        fcorporationtype:[{required: true, message: '请输入单位类型', trigger: 'blur'}],
        findustry:[{required: true, message: '请输入所属行业', trigger: 'blur'}],
        fpaymentmethods:[{required: true, message: '请输入缴费方式', trigger: 'blur'}],
        fuse:[{required: true, message: '请输入用途', trigger: 'blur'}],
        fispaid:[{required: true, message: '请输入是否有偿', trigger: 'blur'}],
        fcreatetime:[{required: true, message: '请输入开始日期', trigger: 'blur'}],
        ffinishedtime:[{required: true, message: '请输入办结日期', trigger: 'blur'}],
        fprjtype:[{required: true, message: '请输入项目类型', trigger: 'blur'}],
        fprjfrom:[{required: true, message: '请输入项目来源', trigger: 'blur'}],
      },
      //导入申请单
      openImport: false,
      //对话框中的信息是否可编辑
      canEdit: true,
    };
  },
  watch: {
    form(val) {
      console.log("form发生修改了");
      this.formIsChange = true;
    },
  },
  created() {
    this.getList();
    //预先加载省市区数据
    this.getCountySelect();
    //获取客户信息并缓存本地
    miniListCustomer().then((response) => {
       this.customerInfoOptions = response.rows;
       localStorage.setItem("customerList",JSON.stringify(response.rows));
    });
    //预先获取客户信息数据
    var customerList = localStorage.getItem("customerList");
    this.customerInfoOptions = JSON.parse(customerList);
  },
  methods: {
    /** 查询测试样例列表 */
    getList() {
      this.loading = true;
      listMateri(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.tableData = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fguid: undefined,
        fcorporationname: undefined,
        flegalperson: undefined,
        faddress: undefined,
        fzipcode: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.fguid);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getCompanyTypeSelect();
      this.getIndustrySelect();
      this.open = true;
      this.formMode = "Add";
      this.form.fguid = guid();
      this.$set(this.form,'fcreateperson',this.$store.state.user.name);
      this.$set(this.form,'fcreatetime',new Date());
      this.form.fsendmaporg = "甘肃基础地理信息中心";
      this.title = "添加申请单";
      this.activeMainTabName = "applyDocTab";
      this.firstTabIsShow = true;
      this.formIsChange = false;
      this.canEdit = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getCompanyTypeSelect();
      this.getIndustrySelect();
      this.formMode = "Update";
      const id = row.fguid || this.ids;
      getMateri(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改申请单";
        this.activeMainTabName = "applyDocTab";
        this.firstTabIsShow = true;
        this.formIsChange = false;
        this.canEdit = true;
      });
    },
    /**查看按钮操作 */
    handleView(row) {
      this.reset();
      this.getCompanyTypeSelect();
      this.getIndustrySelect();
      this.formMode = "View";
      const id = row.fguid || this.ids;
      getMateri(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改申请单";
        this.activeMainTabName = "applyDocTab";
        this.firstTabIsShow = true;
        this.formIsChange = false;
        this.canEdit = false;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.formMode == "Update") {
            updateMateri(this.form).then((response) => {
              if (response.code === 200) {
                this.form = response.data;
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else if(this.formMode == "Add"){
            addMateri(this.form).then((response) => {
              if (response.code === 200) {
                this.form = response.data;
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.fguid || this.ids;
      const fbillcode = row.fbillcode || this.fbillcode;
      this.$confirm(
        '是否确认删除分发编号为"' + fbillcode + '"的申请单?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delMateri(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "result/materi/export",
        {
          id : '111111111',
        },
        `system_demo.xlsx`
      );
    },
    //发图单返回状态
    formatterStatus(row, column) {
      switch (row.freturnsituation) {
        case "staReturned":
          return "已返回";
          break;
        case "staUnReturned":
          return "未返回";
          break;
        default:
          return "未知";
      }
    },
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property];
      if (data == null) {
        return null;
      }
      let dt = new Date(data);
      return dt.getFullYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();
    },
    //分发状态
    formatterIssuesStatus(row, column) {
      switch (row.fissuedstate) {
        case "staHandling":
          return "正在进行";
          break;
        case "staHandled":
          return "已分发";
          break;
        default:
          return "未知";
      }
    },
    selectBlur(e) {
      console.log("selectBlur");
      this.form.fcorporationname = e.target.value;
      this.form.fcorporationid = "";
    },
    selectCustomer(item){
      console.log("item:"+item);
      var filterArr = this.customerInfoOptions.filter(function(p){
           return p.fcorporationname === item;
      });
      if((filterArr)&&(filterArr.length>0)){
        getCustomer(filterArr[0].fguid).then((response) => {
          if(response.data){
            //此处不能直接对属性进行赋值，因为初始没有这些属性，vue未对其初始化getter和setter方法，导致赋值后无法改变其值
            this.$set(this.form,'fcorporationid',response.data.fguid);
            this.$set(this.form,'flegalperson',response.data.flegalperson);
            this.$set(this.form,'faddress',response.data.faddress);
            this.$set(this.form,'fzipcode',response.data.fzipcode);
            this.$set(this.form,'fcorporationtype',response.data.fcorporationtype);
            this.$set(this.form,'fcoandmanager',response.data.fcoandmanager);
            this.$set(this.form,'fcontacttel',response.data.fcontacttel);
            this.$set(this.form,'findustry',response.data.findustry);
            this.$set(this.form,'forgcreditnum',response.data.forgcreditnum);
            this.$set(this.form,'fischeckedqa',response.data.fischeckedqa);
            this.$set(this.form,'fcheckeddate',response.data.fcheckeddate);
            this.$set(this.form,'fcounty',response.data.fcounty);
          }else{
            this.form.fcorporationid = "";
          }
        });
      }else{
        this.form.fcorporationid = "";
      }
    },
    /** 查询所处县下拉树结构 */
    getCountySelect() {
      if (!this.countyOptions || this.countyOptions.length <= 0) {
        var countyList = localStorage.getItem("countyOptions");
        //console.log("countyList:"+countyList);
        if (countyList) {
          this.countyOptions.push(JSON.parse(countyList));
        }
          listCounty().then((response) => {
            this.countyOptions = [];
            const county = { fcode: 0, fcontent: "所处县市", children: [] };
            county.children = this.handleTree(
              response.data,
              "fcode",
              "fparentcode",
              null,
              "-1"
            );
            this.countyOptions.push(county);
            localStorage.setItem("countyOptions", JSON.stringify(county));
          });
      }
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.fcode,
        label: node.fcontent,
        children: node.children,
      };
    },

    /** 查询单位类型下拉树结构 */
    getCompanyTypeSelect() {
      var param = new Object();
      param.fscope = "客户信息_单位类型";
      listDataDic(param).then((response) => {
        this.companyTypeOptions = [];
        const dicList = { fcode: 0, fcontent: "单位类型", children: [] };
        dicList.children = this.handleTree(
          response.data,
          "fcode",
          "fparentcode",
          null,
          "-1"
        );
        this.companyTypeOptions.push(dicList);
      });
    },

    /** 查询所属行业下拉树结构 */
    getIndustrySelect() {
      var param = new Object();
      param.fscope = "客户信息_所属行业";
      listDataDic(param).then((response) => {
        this.industryOptions = [];
        this.industryOptions = response.data;
      });
    },
    handleClick(tab) {
      console.log("触发handleClick");
      if (tab.name == "diliguoqing") {
        this.$refs["diliguoqing"].getOrderList(this.form);
        console.log("地理国情数据");
      } else if (tab.name == "hangshe") {
        this.$refs["hangshe"].getOrderList(this.form);
        console.log("航摄成果");
      } else if (tab.name == "jiami") {
        this.$refs["jiami"].getOrderList(this.form);
        console.log("加密成果");
      } else if (tab.name == "weixing") {
        this.$refs["weixing"].getOrderList(this.form);
        console.log("卫星影像");
      } else if (tab.name == "qita") {
        this.$refs["qita"].getOrderList(this.form);
        console.log("其他");
      }
    },
    handleMainTabClick(tab) {
      if (tab.name == "applyDocTab") {
        console.log("切换到申请单Tab页");
      } else if (tab.name == "orderItemTab") {
        console.log("切换到订单明细Tab页");
        if (this.checkApplyDocIsSave()) {
          if (this.activeName == "" || this.activeName == "0") {
            this.activeName = "diliguoqing";
          }
        } else {
          console.log("返回false，需要退回到申请单页");
          this.activeMainTabName = "applyDocTab";
        }
      }
    },
    nextStep() {
      this.checkApplyDocIsSave();
    },
    backStep() {
      this.activeMainTabName = "applyDocTab";
      this.firstTabIsShow = true;
      this.formIsChange = false;
    },
    showDefaultItemTab() {
      if (this.activeName == "" || this.activeName == "0") {
        console.log("this.activeName:" + this.activeName);
        this.activeName = "diliguoqing";
        console.log("this.activeName:" + this.activeName);
      }
      this.$refs[this.activeName].getOrderList(this.form);
    },
    saveApplyDocSave() {
      this.$refs["form"].validate((valid) => {
        console.log("formMode :" + this.formMode);
        if (valid) {
          if (this.formMode == "Update") {
            updateMateri(this.form).then((response) => {
              if (response.code === 200) {
                this.form = response.data;
                this.getList();
                this.activeMainTabName = "orderItemTab";
                this.showDefaultItemTab();
                this.firstTabIsShow = false;
                this.formIsChange = false;
              }
            });
          } else {
            //点击确定的操作(调用接口)
            addMateri(this.form).then((response) => {
              console.log("新增api调用结果：" + response.code);
              if (response.code === 200) {
                this.form = response.data;
                this.getList();
                this.formMode = "Update";
                this.activeMainTabName = "orderItemTab";
                this.showDefaultItemTab();
                this.firstTabIsShow = false;
                this.formIsChange = false;
              }
            });
          }
        }
      });
    },
    checkApplyDocIsSave() {
      var applyForm = this.form;
      var formMode = this.formMode;
      console.log(applyForm);
      if(this.formMode == "View"){
          this.activeMainTabName = "orderItemTab";
          this.showDefaultItemTab();
          this.firstTabIsShow = false;
          this.formIsChange = false;
      }else if (this.formIsChange || this.formMode == "Add") {
        this.$confirm("此操作需要将当前申请单数据保存, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.saveApplyDocSave();
          })
          .catch(() => {
            //几点取消的提示
            console.log("取消");
          });
      } else if(this.formIsChange || this.formMode == "Update"){
        this.saveApplyDocSave();
      }
    },
    handleImport(){
      this.openImport = true;
    },
  },
};
</script>
